<template>
	<view class="container">
		<!-- <view class="top-banner"> -->
			<image style="width:750rpx;" :src="$img_base_url(img)" mode="widthFix"></image>
		<!-- </view> -->
		<!-- <view class="content">
			<view class="form-box"> -->
		<!-- <view class="form-item row border">
					<view class="label"> *供应商名称 </view>
					<view class="form-content">
						<view class="input-box">
							<input v-model="params.shopname" type="text" placeholder="请输入供应商名称"
								placeholder-class="pla-class" />
						</view>
					</view>
				</view> -->
		<!-- <view class="form-item row border">
					<view class="label"> 地址 </view>
					<view class="form-content">
						<view class="select-box" @click="openMap">
							<text v-if="!params.city" class="pla-class">请选择地址</text>
							<text v-else class="select-value">{{ params.address }}</text>
							<image :src="$img_path('/mine/chevron_right.png')" mode="widthFix"></image>
						</view>
					</view>
				</view> -->
		<!-- <view class="form-item row border">
					<view class="label">
						详细地址
					</view>
					<view class="form-content">
						<view class="input-box">
							<input type="text" placeholder="请输入详细地址" placeholder-class="pla-class" />
						</view>
					</view>
				</view> -->
		<!-- <view class="form-item column border">
					<view class="label"> 主营项目 </view>
					<view class="form-content">
						<view class="textarae-box">
							<textarea class="textarea" placeholder="请填写主营项目" placeholder-class="pla-class"
								v-model="params.content"></textarea>
						</view>
					</view>
				</view> -->

		<!-- <view class="form-item row border">
					<view class="label"> *姓名 </view>
					<view class="form-content">
						<view class="input-box">
							<input v-model="params.name" type="text" placeholder="请输入您的真实姓名"
								placeholder-class="pla-class" />
						</view>
					</view>
				</view> -->
		<!-- <view class="form-item row border">
					<view class="label"> *联系电话 </view>
					<view class="form-content">
						<view class="input-box">
							<input v-model="params.mobile" type="text" placeholder="请输入您的联系电话"
								placeholder-class="pla-class" />
						</view>
					</view>
				</view> -->

		<!-- <view class="form-item column border">
          <view class="label"> 备注 </view>
          <view class="form-content">
            <view class="textarae-box">
              <textarea
              class="textarea"
                placeholder="请填写备注信息"
                placeholder-class="pla-class"
              ></textarea>
            </view>
          </view>
        </view> -->

		<!-- <view class="form-item column">
					<view class="label"> *请上传营业执照 </view>
					<view class="form-content">
						<view class="image-box">
							<view class="i-img" v-for="(i, index) in imgList" :key="index">
								<image class="z-img" :src="i.fullurl" mode="aspectFill"></image>
								<image @click="deleteImg(index)" class="del-icon" :src="$img_path('/pagesMine/63.png')"
									mode="widthFix"></image>
							</view>
							<view class="i-img">
								<image @click="uploadImg()" class="z-img" :src="$img_path('/pagesMine/64.png')"
									mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view> -->
		<!-- 	</view>
		</view> -->

		<!-- 同意权限 -->
		<!--   <view class="check-xy" @click="isCheck = !isCheck">
      <image v-if="isCheck" :src="$img_path('/pagesMine/60.png')" mode="widthFix"></image>
      <image v-else :src="$img_path('/pagesMine/61.png')" mode="widthFix"></image>
      <view> 我已阅读并同意<text @click="openAgreement">《入驻申请协议》</text> </view>
    </view> -->

		<view class="submit-btn">
			<button @click="submit(url)">复制地址</button>
		</view>

		<!-- <popupBox ref="selectCity" type="bottom" :isSlot="true">
      <view class="select-city-box">
        <view class="title">
          <text>请选择省市区</text>
          <image :src="$img_path('/mall/15.png')" @click="closeSelectCity" mode="widthFix"></image>
        </view>

        <view class="s-value">
          <view class="province" @click="check(0)">
            {{ province ? province.text : "选择省份" }}
          </view>
          <view class="city" v-if="province" @click="check(1)">
            {{ city ? city.text : "请选择" }}
          </view>
          <view class="arae" v-if="city" @click="check(2)">
            {{ arae ? arae.text : "请选择" }}
          </view>
        </view>
        <view class="s-list">
          <view class="s-item">
            <text>A</text>
            <view class="name"> 安徽省 </view>
          </view>
          <view class="s-item">
            <text>B</text>
            <view class="name" v-for="item in 4" @click="selectChange()"> 北京 </view>
          </view>
        </view>
      </view>
    </popupBox> -->
	</view>
</template>

<script>
	import {
		BASE_URL
	} from "@/utils/env.js";
	import popupBox from "@/components/popup/popup.vue";
	import {
		getlocation
	} from "@/utils/api/public.js";
	import {
		supplierJoin
	} from "@/utils/api/serviceApi.js";
	import {
		getSysPage,
		getSysConfig
	} from "@/utils/api/userApi.js";
	export default {
		components: {
			popupBox,
		},
		data() {
			return {
				select_city_index: 0,
				province: null,
				city: null,
				arae: null,
				isCheck: false,
				params: {
					shopname: "", //供应商名称
					city: "", //地址
					address: "", //详细地址
					content: "", //经营类型
					name: "", //姓名
					mobile: "", //联系电话
					remark: "", //备注
					image: "", //营业执照
				},
				imgList: [], // 上传的图片
				url: '',
				img: ''
			};
		},
		onLoad() {
			this.article();
			this.ruzhu_url()
			this.ruzhu_img()
		},
		methods: {
			async ruzhu_url() {
				const {
					code,
					data
				} = await getSysConfig({
					site: "ruzhu_url"
				})
				if (code == 1) {
					this.url = data
				}
			},
			async ruzhu_img() {
				const {
					code,
					data
				} = await getSysConfig({
					site: "ruzhu_img"
				})
				if (code == 1) {
					this.img = data
				}
			},
			article() {
				getSysPage({
					biaoshi: "biaoshi",
				}).then((res) => {
					console.log(res);
				});
			},
			selectChange() {
				console.log();
				if (this.select_city_index == 0) {
					this.province = {
						text: "北京",
						value: 1,
					};
					this.select_city_index = 1;
					this.city = null;
					this.arae = null;
				} else if (this.select_city_index == 1) {
					this.city = {
						text: "北京",
						value: 2,
					};
					this.select_city_index = 2;
					this.arae = null;
				} else {
					this.arae = {
						text: "北京",
						value: 2,
					};
				}
			},
			check(type) {
				this.select_city_index = type;
			},
			closeSelectCity() {
				this.$refs.selectCity.close();
			},

			submit(value) {
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功'
						})
					}
				});
				// const {
				// 	shopname,
				// 	city,
				// 	content,
				// 	name,
				// 	mobile
				// } = this.params;
				// if (!this.isCheck || !shopname || !city || !content || !name || !mobile || !this.imgList.length) {
				// 	let tip = "";
				// 	if (!this.isCheck) tip = "请勾选入驻申请协议";
				// 	else if (!shopname) tip = "请输入供应商名称";
				// 	else if (!city) tip = "请选择地址";
				// 	else if (!content) tip = "请输入经营类型";
				// 	else if (!name) tip = "请输入联系人";
				// 	else if (!mobile) tip = "请输入联系电话";
				// 	else if (!this.imgList.length) tip = "请上传营业执照";
				// 	uni.showToast({
				// 		title: tip,
				// 		icon: "none"
				// 	});
				// 	return;
				// }
				// this.params.image = this.imgList.map((item) => item.url).join(",");
				// supplierJoin(this.params).then((res) => {
				// 	uni.redirectTo({
				// 		url: `/pagesMine/supplier/success`
				// 	});
				// });
			},

			// 打开地图获取位置
			openMap() {
				uni.getLocation({
					type: "gcj02",
					success: (res) => {
						let {
							latitude,
							longitude
						} = res;
						getlocation({
							lat: latitude,
							lng: longitude
						}).then((data) => {
							let {
								province,
								city,
								district
							} = data.data.regeocode.addressComponent;
							uni.chooseLocation({
								latitude: latitude,
								longitude: longitude,
								success: (success) => {
									this.params.city = `${province}${city}${district}`;
									this.params.address = success.address;
									console.log(this.params);
								},
							});
						});
					},
				});
			},

			// 切换
			isAgreementToggle() {
				this.isAgreement = !this.isAgreement;
			},
			// 上传图片
			uploadImg() {
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: BASE_URL + "/api/common/upload",
							filePath: tempFilePaths[0],
							name: "file",
							header: {
								token: uni.getStorageSync("token"),
							},
							success: (uploadFileRes) => {
								let data = JSON.parse(uploadFileRes.data);
								if (data.code == 1) {
									this.imgList.push(data.data);
								}
							},
						});
					},
				});
			},
			// 删除图片
			deleteImg(index) {
				this.imgList.splice(index, 1);
			},
			openAgreement() {
				uni.navigateTo({
					url: "/pagesRegion/servicePersonnelReview/agreement",
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.container {
		.top-banner {
			width: 100%;
			height: 436rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.content {
			padding: 0 22rpx;
			box-sizing: border-box;
			margin-top: -68rpx;
			position: relative;
			z-index: 1;

			.form-box {
				background-color: #ffffff;
				border-radius: 20rpx;
				padding: 16rpx 0 64rpx;

				.form-item {
					padding: 24rpx 18rpx 22rpx 24rpx;
					display: flex;

					.label {
						font-weight: bold;
						font-size: 32rpx;
						color: #000000;
						line-height: 44rpx;
					}

					.form-content {
						/deep/ .pla-class {
							font-weight: 500;
							font-size: 28rpx;
							color: #b4b4b4;
							line-height: 40rpx;
						}

						.input-box {
							width: 100%;

							input {
								text-align: right;
							}
						}

						.select-box {
							display: flex;
							justify-content: flex-end;
							align-items: center;

							image {
								width: 32rpx;
								height: 32rpx;
								margin-left: 12rpx;
							}
						}

						.textarae-box {
							width: 100%;
							padding: 4rpx 22rpx;
							box-sizing: border-box;
							max-height: 300rpx;

							textarae {
								width: 100%;
								height: 100%;
							}
						}

						.image-box {
							display: flex;
							flex-wrap: wrap;

							.i-img {
								width: 160rpx;
								height: 160rpx;
								position: relative;
								margin-right: 20rpx;

								.z-img {
									width: 100%;
									height: 100%;
									border-radius: 20rpx;
								}

								.del-icon {
									position: absolute;
									right: 10rpx;
									top: 10rpx;
									width: 40rpx;
									height: 40rpx;
								}
							}
						}
					}

					&.border {
						border-bottom: 2rpx solid #eeeeee;
					}

					&.row {
						flex-direction: row;
						align-items: center;
						justify-content: space-between;

						.label {
							width: 180rpx;
						}

						.form-content {
							width: calc(100% - 180rpx);
						}
					}

					&.column {
						flex-direction: column;

						.form-content {
							margin-top: 20rpx;
							width: 100%;
						}
					}
				}
			}
		}

		.submit-btn {
			// position: sticky;
			// bottom: 0;
			// left: 0;
			// right: 0;
			// z-index: 3;
			width: 100%;
			background-color: #ffffff;
			padding: 20rpx 22rpx 0;
			padding-bottom: calc(constant(safe-area-inset-bottom) + 20rpx);
			padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
			margin-top: 26rpx;
			box-sizing: border-box;

			button {
				width: 100%;
				height: 96rpx;
				background: linear-gradient(135deg, #ffa233 0%, #fb4c4c 100%);
				border-radius: 80rpx;
				font-weight: bold;
				font-size: 36rpx;
				color: #ffffff;
				line-height: 96rpx;
			}
		}
	}

	.select-city-box {
		.title {
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			padding-top: 28rpx;

			text {
				font-weight: bold;
				font-size: 36rpx;
				color: #333333;
				line-height: 50rpx;
			}

			image {
				position: absolute;
				top: 32rpx;
				right: 22rpx;
				width: 41rpx;
				height: 41rpx;
			}
		}

		.s-value {
			padding: 66rpx 22rpx 32rpx;
			box-sizing: border-box;
			display: flex;

			&>view {
				font-weight: bold;
				font-size: 28rpx;
				color: #000000;
				line-height: 40rpx;

				&:not(:first-child) {
					margin-left: 120rpx;
				}
			}
		}

		.s-list {
			width: 100%;
			height: 582rpx;
			overflow-y: auto;
			padding: 0 22rpx 50rpx;
			box-sizing: border-box;

			.s-item {
				width: 100%;
				padding-left: 30rpx;
				box-sizing: border-box;
				position: relative;

				&>text {
					position: absolute;
					font-weight: 500;
					font-size: 28rpx;
					color: #000000;
					line-height: 40rpx;
					left: 0;
					top: 0;
				}

				.name {
					font-weight: 500;
					font-size: 28rpx;
					color: #000000;
					line-height: 40rpx;
					margin-bottom: 48rpx;
				}
			}
		}
	}

	.check-xy {
		display: flex;
		align-items: center;
		margin-top: 26rpx;
		margin-left: 24rpx;

		&>image {
			width: 30rpx;
			height: 30rpx;
		}

		view {
			font-weight: 400;
			font-size: 24rpx;
			color: #333333;
			line-height: 34rpx;
			padding-left: 12rpx;
			box-sizing: border-box;

			text {
				color: #e72a2a;
			}
		}
	}

	.textarea {
		min-height: 80rpx;
		height: 100%;
	}
</style>